package com.pengtu.gsj.controller.lwfw;

import javax.servlet.http.HttpServletRequest;




import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.lwfw.Trafficservice;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.lwfw.TrafficserviceService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

@Controller
@RequestMapping("trafficservice")
public class TrafficserviceController extends DefaultBaseController {

	@Autowired
	public TrafficserviceService trafficserviceService;
	
	/**
	 * 加载
	 * @param id
	 * @return
	 */
	@ModelAttribute
	public Trafficservice load(String id){
		Trafficservice trafficservice;
		if(StringUtils.isNotEmpty(id)){
			trafficservice = trafficserviceService.getTrafficserviceById(id);
		}else{
			trafficservice = new Trafficservice();
		}
		return trafficservice;
	}
	
	/**
	 * 页面跳转
	 * @return
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showLisfInfo() {
		return "lwfw/trafficservice_list";
	}
	
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	@ResponseBody
	public Page<Trafficservice> getRoadMaterialList(Page<Trafficservice> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("createDate");
			page.setOrder(Page.DESC);
		}
		page = trafficserviceService.findTrafficservice(page,queryFilter);
		return page;
	}
	
	/**
	 * 保存
	 * @param roadMaterial
	 * @return
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveRoadCycle(@ModelAttribute Trafficservice Trafficservice){
		trafficserviceService.saveTrafficservice(Trafficservice);
		return true;
	}
	
	
	/**
	 * 加载数据
	 * @param infoManagement
	 * @return
	 */
	@RequestMapping(value="show")
	@ResponseBody                                                     
	public Trafficservice showRoadCycle (@ModelAttribute Trafficservice Trafficservice){
		return Trafficservice;
	}
	
	/**
	 * 删除
	 * @param infoManagement
	 * @return
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean delateInfoManagement(@ModelAttribute Trafficservice Trafficservice){
		trafficserviceService.delateTrafficservice(Trafficservice);
		return true;
	}
	
	 /**
	  * 
	  * checkSerType:
	  * 适用:新增和修改公众出行信息服务时，ajax判断菜单服务手段名称在数据库中是否已经存在
	  * @return  返回true或false  json数据
	  * @exception 
	  * @since  1.0.0
	  */
	@ResponseBody
	@RequestMapping(value = "checkSerType", produces = "application/json; charset=utf-8")
	public Boolean checkSerType() {
		String serviceType = SpringMvcUtils.getParameter("serviceType");
		String id = SpringMvcUtils.getParameter("id");
		return trafficserviceService.checkServiceType(serviceType, id);
	}
}
